package com.example.demo.service.impl;

import com.example.demo.dto.Author;

import com.example.demo.dto.Book;
import com.example.demo.service.FindBooksService;
import lombok.var;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Allen.Lv
 * @Description 数据赋值类
 * @Date 15:05 2019/2/21
 * @Desc: Coding Happy!
 **/
@Service
@Component
public class FindBooksServiceImpl implements FindBooksService {

    /**
     * 模拟数据库填充数据操作
     * @return
     */
    @Override
    public List<Book> findBooks() {
        var books = new ArrayList<Book>();
        for (Integer count = 0; count < 10; count++) {
            books.add(setBook(count));
        }
        return books;
    }

    public Book setBook(Integer count) {
        var book = new Book();
        var author = new Author();
        author.setId(count);
        author.setName("作者" + count);
        author.setAge(count);

        book.setId(count);
        book.setName("名字" + count);
        book.setAuthor(author);
        book.setPublisher("出版社" + count);
        return book;
    }

}
